package cn.fl.bizflow.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.bizflow.dto.RskUsrAchLogDTO;
import cn.fl.bizflow.service.IRskUsrAchLogApiService;
import cn.fl.bizflow.service.IRskUsrAchLogService;
import cn.fl.bizflow.transform.RskUsrAchLogVOTransform;
import cn.fl.bizflow.vo.RskUsrAchLogVO;
import cn.fl.framework.base.context.CurrentThreadContext;


/**
 * @Description: 用户提成记录表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class RskUsrAchLogServiceImpl implements IRskUsrAchLogService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(IRskUsrAchLogService.class);
	
	@Autowired
	private IRskUsrAchLogApiService rskUsrAchLogApiService;
	
	
	@Override
	public RskUsrAchLogVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		//TODO 业务逻辑
		RskUsrAchLogDTO dto = null;//this.自定义ApiService.selectById(id);
		return RskUsrAchLogVOTransform.toVO(dto);
	}

	@Override
	public Long add(RskUsrAchLogVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		//return this.rskUsrAchLogApiService.add(RskUsrAchLogVOTransform.toDTO(entity));
		//TODO 业务逻辑
		return null;
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.rskUsrAchLogApiService.removeById(id);
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info( logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(RskUsrAchLogVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info( logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.rskUsrAchLogApiService.modify(RskUsrAchLogVOTransform.toDTO(entity));
		//TODO 业务逻辑
		return false;
	}

	@Override
	@SuppressWarnings("unchecked")
	public Pager searchListPage(Pager page) throws BaseException{
	     if (page == null || page.getCondition() == null) {
	            return page;
	        }
	       page = this.rskUsrAchLogApiService.searchListPage(page);
	       
	       
	   /*    List<RskUsrAchLogVO> voList = RskUsrAchLogVOTransform.toVOList((List<RskUsrAchLogDTO>) page.getResultList());
		  if(CurrentThreadContext.getCurrentOrgCd().contains(RskUsrAchLogConstant.CODE_RSK_USR_ACH_LOG_FILE_ORG_CD)){
	          //人力资源
			  return page;
	      }else{
	    	 List<RskUsrAchLogVO> newlist =new  ArrayList<RskUsrAchLogVO>();
	    	 for (RskUsrAchLogVO rskUsrAchLogVO : voList) {
	    		 if(rskUsrAchLogVO.getUsrOrgCd().contains(CurrentThreadContext.getCurrentOrgCd())){
	    			 newlist.add(rskUsrAchLogVO);
	    		 }
			}
	    	 page.setResultList(newlist); 
	      }*/
			
		return  page;
	}
	
	 /**
     * 绩效批量新增
     *
     * @param 
     * @return
     */
    public boolean add(List<RskUsrAchLogVO> entity) throws BaseException {
        if (CollectionUtils.isEmpty(entity)) return false;
        return this.rskUsrAchLogApiService.add(RskUsrAchLogVOTransform.toDTOList(entity));
    }
}
